package com.bigflexlib.core.dependency
{
	
	

	/**
	 * 
	 * Stores the information related to a dependency. It is passed to a DependencyHelper.
	 * 
	 * <p>
	 * Why is it named "Dependency<b><u>Spec</u></b>" instead of "Dependency"??
	 * Well, because it is not the actual dependency, but a specification of its lifecycle within
	 * the owner.
	 * </p>
	 * 
	 * @author aldo.bucchi@gmail.com
	 * 
	 * @see com.bigflexlib.core.dependency.DependencyHelper
	 * @see com.bigflexlib.x.flash.events.EventListenerSpec
	 * 
	 */	
	public class DependencySpec
	{
		
		
		/**
		 * 
		 *  A String, QName, or int specifying the value used to access the property in the owner object,
		 * 
		*/		
		public var property:Object;
		
		
		public var changeEventType:String;
		
		
		public var eventListenerSpecs:Array = [];
		
		
		public var dispatchPropertyChangeEvent:Boolean;
		
		
		public var defaultValue:*;



		internal var isUsingDefault:Boolean = true;



		/**
	     *  @param property
	     *  A String, QName, or int specifying the value used to access the property in the owner object,
		 * 
		 * 
		 * @param changeEventType
		 *   If you pass a value, then a flash.events.Event with this type will be dispatched after this property
		 *   has changed and an update() has been called. If you wish to dispatch a custom event you can do it manually from within the update().
		 *   If you pass a wildcard ( "*" ), then the type will be automatically set to {property}Changed  ( valueChanged, priceChanged, etc )
		 * 
		 * @param eventListenerSpecs
		 *   An array of EventListenerSpec objects to specify any event listeners that should be automatically
		 *   added and removed to this dependency. Event listener specs are added when the property is set() and removed when it is replaced
		 *   by a new value.
		 * 
		 * @param dispatchPropertyChangeEvent 
		 *   If this flag is set to true a PropertyChangeEvent will be automatically constructed and dispatched for this property, with the
		 *   correct values for all its properties, including "oldValue" and "newValue"
		 * 
		 * 
		 * @see mx.events.PropertyChangeEvent
		 * 
		 */
		public function DependencySpec( property:Object, changeEventType:String = null, eventListenerSpecs:Array = null, dispatchPropertyChangeEvent:Boolean = false, defaultValue:* = undefined )
		{

			this.property = property;

			
			if ( changeEventType == "*" ) // convention
				changeEventType = property + "Changed";


			this.changeEventType = changeEventType;
		
			this.eventListenerSpecs = eventListenerSpecs == null ? [] : eventListenerSpecs;
		
			this.dispatchPropertyChangeEvent = dispatchPropertyChangeEvent;
		
			this.defaultValue = defaultValue;
			
		}
		
		
		
		/* handy code snippet


		private var Spec:DependencySpec = new DependencySpec( "", "Changed" );
		[Bindable("Changed")]
		public function get ( ):
		{
			return dh.getDependencyValue( Spec );
		}

		public function set ( v: ):void
		{
			dh.setDependencyValue( Spec, v );
		}

		 
		 
		 */
		
		

		
	}

}